<template>
  <div id="online" class="app-container">
    <add v-if="showDialog" @close="closeDialog" @update="getOnlineList"></add>
    <el-button type="primary" icon="el-icon-plus" class="button" @click="showDialog=!showDialog">添加</el-button>
    <el-table :data="onlineData" border style="width: 100%" class="onlineTable">
      <el-table-column prop="id" label="序号" min-width="80"></el-table-column>
      <el-table-column prop="retailersName" label="电商名称" width="120"></el-table-column>
      <el-table-column prop="activeUsers" label="活跃用户" width="100"></el-table-column>
      <el-table-column prop="yesterdayUsers" label="昨日用户数" min-width="120"></el-table-column>
      <el-table-column prop="yesterdayOrders" label="昨日订单数" width="150"></el-table-column>
      <el-table-column prop="sumUsers" label="累计用户" width="100"></el-table-column>
      <el-table-column prop="sumInvestors" label="累计投资用户数" width="150"></el-table-column>
      <el-table-column prop="sumInvestNumber" label="累计投资笔数" width="120"></el-table-column>
      <el-table-column prop="flag" label="着陆标签" width="100"></el-table-column>
      <el-table-column prop="rebateAmonut" label="生成链接" width="110"></el-table-column>
      <el-table-column prop="publishStatus" label="状态" width="120"></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="size">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import add from '../addDialog'
  import { retailersList } from 'api/retailers'
  export default {
    components: {
      add
    },
    data() {
      return {
        onlineData: [],
        pageSize: 10,
        curPage: 1,
        showDialog: false,
        size: 0
      }
    },
    created() {
      this.getOnlineList()
    },
    methods: {
      async getOnlineList() {
        this.closeDialog()
        const parm = {
          pageSize: this.pageSize,
          curPage: this.curPage - 1
        }
        try {
          let back = await retailersList(parm)
          back = back.data
          if (back.resultCode === '200') {
            console.log(back.result)
            this.size = back.size
            this.onlineData = back.result
          }
        } catch (err) {
          this.$alert('请求出错', '提示')
        }
      },
      closeDialog() {
        this.showDialog = false
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.getOnlineList()
      },
      handleCurrentChange(val) {
        this.curPage = val
        this.getOnlineList()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .onlineTable {
    margin-top: 15px;
  }

  .block {
    margin-top: 15px;
    float: right;
  }
</style>
